using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LyncTalker
{
    public delegate void VoiceChanged(string voiceName);

    public partial class Configuration : Form
    {
        public event VoiceChanged VoiceChanged;

        public bool SpeakFirstName { get; private set; }

        public bool SpeakLastName { get; private set; }

        public Configuration()
        {
            InitializeComponent();
            voiceComboBox.SelectedValueChanged += voiceComboBox_SelectedValueChanged;

            if (LyncTalker.Properties.Settings.Default.SpeakFirstName)
            {
                SpeakFirstName = true;
                firstNameCheckBox.Checked = true;
            }
            else
            {
                firstNameCheckBox.Checked = false;
                SpeakFirstName = false;
            }

            if (LyncTalker.Properties.Settings.Default.SpeakLastName)
            {
                lastNameCheckBox.Checked = true;
                SpeakLastName = true;
            }
            else
            {
                lastNameCheckBox.Checked = false;
                SpeakLastName = false;
            }
        }

        void voiceComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            if (voiceComboBox.SelectedItem != null)
                if (VoiceChanged != null)
                {
                    var voiceName = voiceComboBox.SelectedItem.ToString();
                    LyncTalker.Properties.Settings.Default.VoiceName = voiceName;
                    LyncTalker.Properties.Settings.Default.Save();
                    VoiceChanged(voiceName);
                   
                }

            
        }

        public void AddVoice(string voiceName)
        {
            voiceComboBox.Items.Add(voiceName);
            SetActiveVoice(voiceComboBox.Items[0].ToString());
        }

        public void SetActiveVoice(string voiceName)
        {
            voiceComboBox.Text = voiceName;
        }

        private void LoadSettings(object sender, EventArgs e)
        {
            
        }

        private void SaveSettings(object sender, FormClosingEventArgs e)
        {
            // If the user clicked "Save"
            if (this.DialogResult == DialogResult.OK)
            {
                LyncTalker.Properties.Settings.Default.Save();
            }
        }

        private void firstNameCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (firstNameCheckBox.Checked == true)
            {
                SpeakFirstName = true;
                LyncTalker.Properties.Settings.Default.SpeakFirstName = true;
            }
            else
            {
                SpeakFirstName = false;
                LyncTalker.Properties.Settings.Default.SpeakFirstName = false;
            }

            LyncTalker.Properties.Settings.Default.Save();
        }

        private void lastNameCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (lastNameCheckBox.Checked == true)
            {
                SpeakLastName = true;
                LyncTalker.Properties.Settings.Default.SpeakLastName = true;  
            }
            else
            {
                SpeakLastName = false;
                LyncTalker.Properties.Settings.Default.SpeakLastName = false;
            }

            LyncTalker.Properties.Settings.Default.Save();
        }
    }
}